/// @tags:
#include <cstdio>
#include <functional>
#include <iostream>
#include <numeric>

using std::cin, std::cout, std::endl;

namespace BlueQuantum {

constexpr int maxn = 1e5 + 2;

char str[maxn];

void solve() {
  int n;
  cin >> n >> (str + 1);
  for (int i = 1; i <= n; ++i) {
    if (str[i] == 'R') {
      for (int j = i + 1; j <= n; ++j) {
        if (str[j] == 'L') {
          cout << 0 << '\n';
          return;
        }
      }
      break;
    }
  }
  for (int i = 1; i < n; ++i) {
    if (str[i] == 'L') {
      if (str[i + 1] == 'R') {
        cout << i << '\n';
        return;
      }
    }
  }
  cout << "-1\n";
}

int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("A. Hall of Fame.in", "r", stdin);
  freopen("A. Hall of Fame.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
